package jy.game.components.role;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

import jy.game.AttributeFinalHelper;
import jy.game.AttributeHelper;
import jy.game.BasePojo;
import jy.game.components.item.ItemType;
import jy.game.components.item.JyItemInstance;
import jy.game.components.resource.JyResource;
import jy.game.components.wuxue.JyTrigger;
import jy.game.components.wuxue.box.JyInternalSkillInstance;
import jy.game.components.wuxue.box.JySkillInstance;
import jy.game.components.wuxue.box.JySpecialSkillInstance;
import jy.game.logic.AttackLogic;
import jy.game.tools.CommonSettings;
import jy.game.tools.JyResourceManager;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.ElementList;
import wx.xml.simpleframework.xml.Root;


@Root(name = "role")
public class JyRole extends BasePojo {

    @Attribute(name = "key") public           String key;
    @Attribute(name = "animation") public     String animation;
    @Attribute(name = "name") public          String name;
    @Attribute(name = "head") public          String head;
    @Attribute public                         int    hp;
    @Attribute public                         int    maxhp;
    @Attribute public                         int    mp;
    @Attribute public                         int    maxmp;
    @Attribute public                         int    wuxing;
    @Attribute public                         int    shenfa;
    @Attribute public                         int    bili;
    @Attribute public                         int    gengu;
    @Attribute public                         int    fuyuan;
    @Attribute public                         int    dingli;
    @Attribute public                         int    quanzhang;
    @Attribute public                         int    jianfa;
    @Attribute public                         int    daofa;
    @Attribute public                         int    qimen;
    @Attribute public                         String currentSkillName  = "";
    @Attribute public                         int    exp;
    @Attribute(name = "arena") public         String arenaValue;
    @Attribute(name = "female") public        int    femaleValue;
    @Attribute(name = "jiushen_count") public int    jiushen_count;
    @Attribute public                         int    level;
    @Attribute public                         int    wuxue;
    @Attribute(name = "grow_template") public String growTemplateValue = "default";
    @Attribute(name = "talent") public        String talentValue;
    @Attribute(name = "leftpoint") public     int    leftpoint;

    @ElementList(name = "skills") public          List<JySkillInstance>         skills         = new ArrayList<>();
    @ElementList(name = "internal_skills") public List<JyInternalSkillInstance> internalSkills = new ArrayList<>();
    @ElementList(name = "special_skills") public  List<JySpecialSkillInstance>  specialSkills  = new ArrayList<>();
    @ElementList(name = "items") public           List<JyItemInstance>          equipment      = new ArrayList<>();

    public List<String> talents = new ArrayList<String>();
    // (get) Token: 0x0600045A RID: 1114 RVA: 0x0002E0D8 File Offset: 0x0002C2D8
    // (set) Token: 0x0600045B RID: 1115 RVA: 0x0000462C File Offset: 0x0000282C
    // [XmlIgnore]
//    public JySkillBox CurrentSkill() {
//        JySkillBox skillBox = null;
//        for (JySkillBox skillBox2 : this.GetAvaliableSkills()) {
//            if (skillBox == null) {
//                skillBox = skillBox2;
//            }
//            if (TextUtils.isEmpty(this.currentSkillName) && skillBox2.skillType == SkillType0.Normal) {
//                return skillBox2;
//            }
//            if (skillBox2.name == this.currentSkillName) {
//                return skillBox2;
//            }
//        }
//        return skillBox;
//    }
//
//    void setCurrentSkill(JySkillBox value) {
//        this.currentSkillName = value.name;
//    }


    //    public void AddTalent(String talent) {
//        this.talents.add(talent);
//        RuntimeData.Instance.RefreshTeamMemberPanel(this.key, false, true);
//    }
//
//
//    public boolean RemoveTalent(String talent) {
//        if (this.talents.contains(talent)) {
//            this.talents.remove(talent);
//            RuntimeData.Instance.RefreshTeamMemberPanel(this.key, false, true);
//            return true;
//        }
//        return false;
//    }
    // [XmlIgnore]


    //    public Iterable<JySkillBox> GetAvaliableSkills() {
//        for (JySpecialSkillInstance ss : this.specialSkills) {
//            if (ss.isUsed()) {
//                yield return ss;
//            }
//        }
//        for (JySkillInstance ss2 : this.skills) {
//            if (ss2.isUsed) {
//                yield return ss2;
//                for (UniqueSkillInstance us : ss2.uniqueSkills) {
//                    if (ss2.level >= us.JyUniqueSkill.requireLevel) {
//                        yield return us;
//                    }
//                }
//            }
//        }
//        JyInternalSkillInstance EquippedInternalSkill = this.GetEquippedInternalSkill();
//        if (EquippedInternalSkill != null) {
//            for (UniqueSkillInstance us2 : EquippedInternalSkill.uniqueSkills) {
//                if (EquippedInternalSkill.level >= us2.JyUniqueSkill.requireLevel) {
//                    yield return us2;
//                }
//            }
//        }
//        yield break;
//    }


    //    public Iterable<JyTrigger> GetAllTriggers() {
//        for (JyItemInstance item : this.equipment) {
//            for (JyTrigger t : item.allTriggers) {
//                yield return t;
//            }
//        }
//        for (JySkillInstance s : this.skills) {
//            for (JyTrigger t2 : s.JySkill.triggers) {
//                if (s.level >= t2.level) {
//                    yield return t2;
//                }
//            }
//        }
//        for (JyInternalSkillInstance s2 : this.internalSkills) {
//            for (JyTrigger t3 : s2.internalSkill.triggers) {
//                if (s2.level >= t3.level) {
//                    yield return t3;
//                }
//            }
//        }
//        yield break;
//    }
    // [XmlIgnore]
    public int                  balls;
    // [XmlIgnore]
    public AttributeFinalHelper AttributesFinal;


    //    public String GetAttributeString(String attr) {
//        if (attr == "maxhp") {
//            return this.GetAttributeHpString();
//        }
//        if (attr == "maxmp") {
//            return this.GetAttributeMpString();
//        }
//        return String.format("%s(+%s)", this.Attributes[attr], this.GetAdditionAttribute(attr));
//    }
    // [XmlIgnore]
    public AttributeHelper       Attributes;
    public List<JySkillInstance> Skills_bak = new ArrayList<JySkillInstance>();


//    public boolean AddExp(int add) {
//        boolean flag          = false;
//        int     max_ATTRIBUTE = CommonSettings.MAX_ATTRIBUTE;
//        int     num           = max_ATTRIBUTE;//.Min(3000, max_ATTRIBUTE);
//        this.Exp += add;
//        JyItemInstance equipment = this.GetEquipment(4);
//        // FileLogger.instance.Log("Role.cs:571 %s %s", this.name, equipment);
//        if (equipment != null) {
//            ItemSkill itemSkill = equipment.GetItemSkill();
//            if (itemSkill.isInternal && this.internalSkills.Count < CommonSettings.MAX_INTERNALSKILL_COUNT) {
//                boolean flag2 = false;
//                // FileLogger.instance.Log("Role.cs:571 %s try add inernal skill", this.name);
//                for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//                    if (internalSkillInstance.name.Equals(itemSkill.SkillName)) {
//                        flag2 = true;
//                        if (itemSkill.maxLevel >= internalSkillInstance.level) {
//                            // FileLogger.instance.Log("Role.cs:581 %s add %s exp %s", this.name, itemSkill.SkillName, add);
//                            internalSkillInstance.tryAddExp(add, itemSkill.maxLevel);
//
//                            break;
//                        }
//                        break;
//                    }
//                }
//                if (!flag2) {
//                    JyInternalSkillInstance internalSkillInstance2 = new JyInternalSkillInstance {
//                        name = itemSkill.SkillName,
//                            level = 1,
//                            equipped = 0,
//                            owner = this
//                    } ;
//                    internalSkillInstance2.refreshUniqueSkills();
//                    this.internalSkills.add(internalSkillInstance2);
//                    internalSkillInstance2.tryAddExp(add, 0);
//                }
//            } else if (this.skills.Count < CommonSettings.MAX_SKILL_COUNT) {
//                boolean flag3 = false;
//                // FileLogger.instance.Log("Role.cs:571 %s try add skill", this.name);
//                for (JySkillInstance skillInstance : this.skills) {
//                    if (skillInstance.name.Equals(itemSkill.SkillName)) {
//                        flag3 = true;
//                        if (itemSkill.maxLevel >= skillInstance.level) {
//                            skillInstance.tryAddExp(add, itemSkill.maxLevel);
//                            break;
//                        }
//                        break;
//                    }
//                }
//                if (!flag3) {
//                    JySkillInstance skillInstance2 = new JySkillInstance {
//                        name = itemSkill.SkillName,
//                            level = 1,
//                            owner = this
//                    } ;
//                    skillInstance2.refreshUniqueSkills();
//                    this.skills.add(skillInstance2);
//                    skillInstance2.tryAddExp(add, 0);
//                    flag = true;
//                }
//            } else {
//
//            }
//        }
//        boolean result = false;
//        if (this.level >= CommonSettings.MAX_LEVEL) {
//            this.exp = 0;
//        }
//        while (this.exp > this.levelupExp && this.level < CommonSettings.MAX_LEVEL) {
//            flag = true;
//            int level = this.level;
//            this.level = level + 1;
//            this.leftpoint += 2;
//            this.maxhp += this.GrowTemplate().Attributes.get("hp");
//            if (this.maxhp > CommonSettings.MAX_HPMP) {
//                this.maxhp = CommonSettings.MAX_HPMP;
//            }
//            //// FileLogger.instance.Log("Role.cs:626 " + this.maxhp);
//            this.maxmp += this.GrowTemplate().Attributes.get("mp");
//            if (this.maxmp > CommonSettings.MAX_HPMP) {
//                this.maxmp = CommonSettings.MAX_HPMP;
//            }
//            if (this.bili < max_ATTRIBUTE) {
//                this.bili += this.GrowTemplate().Attributes.get("bili");
//            }
//            if (this.fuyuan < max_ATTRIBUTE) {
//                this.fuyuan += this.GrowTemplate().Attributes.get("fuyuan");
//            }
//            if (this.gengu < max_ATTRIBUTE) {
//                this.gengu += this.GrowTemplate().Attributes.get("gengu");
//            }
//            if (this.dingli < max_ATTRIBUTE) {
//                this.dingli += this.GrowTemplate().Attributes.get("dingli");
//            }
//            if (this.shenfa < max_ATTRIBUTE) {
//                this.shenfa += this.GrowTemplate().Attributes.get("shenfa");
//            }
//            if (this.wuxing < max_ATTRIBUTE) {
//                this.wuxing += this.GrowTemplate().Attributes.get("wuxing");
//            }
//            if (this.quanzhang < max_ATTRIBUTE) {
//                this.quanzhang += this.GrowTemplate().Attributes.get("quanzhang");
//            }
//            if (this.jianfa < max_ATTRIBUTE) {
//                this.jianfa += this.GrowTemplate().Attributes.get("jianfa");
//            }
//            if (this.daofa < max_ATTRIBUTE) {
//                this.daofa += this.GrowTemplate().Attributes.get("daofa");
//            }
//            if (this.qimen < max_ATTRIBUTE) {
//                this.qimen += this.GrowTemplate().Attributes.get("qimen");
//            }
//            if (this.bili > num) {
//                this.bili = num;
//            }
//            if (this.fuyuan > num) {
//                this.fuyuan = num;
//            }
//            if (this.gengu > num) {
//                this.gengu = num;
//            }
//            if (this.dingli > num) {
//                this.dingli = num;
//            }
//            if (this.shenfa > num) {
//                this.shenfa = num;
//            }
//            if (this.wuxing > num) {
//                this.wuxing = num;
//            }
//            if (this.quanzhang > num) {
//                this.quanzhang = num;
//            }
//            if (this.jianfa > num) {
//                this.jianfa = num;
//            }
//            if (this.daofa > num) {
//                this.daofa = num;
//            }
//            if (this.qimen > num) {
//                this.qimen = num;
//            }
//            result = true;
//        }
//        if (flag) {
//            try {
//                RuntimeData.Instance.RefreshTeamMemberPanel(this.key, false, true);
//            } catch (Exception e) {
//                // FileLogger.instance.LogException("Role.cs:705", e);
//            }
//        }
//        return result;
//    }


    //    public boolean CanLearnTalent(String t, ref int need) {
//        int talentCost     = JyResource.getTalentCost(t);
//        int num            = this.Attributes.get("wuxue");
//        int totalWuxueCost = this.getTotalWuxueCost();
//        need = talentCost;
//        return talentCost + totalWuxueCost <= num;
//    }
    public List<JySpecialSkillInstance> SpecialSkills_bak = new ArrayList<JySpecialSkillInstance>();


//    public void addRoundSkillLevel() {
//        int round = RuntimeData.Instance.round;
//        int num   = round / LuaManager.GetConfigInt("NPC_SKILL_LEVEL_ADD_BY_ZHOUMU");
//        if (num > 0) {
//            for (JySkillInstance skillInstance : this.skills) {
//                skillInstance.level += num;
//                if (skillInstance.level > CommonSettings.MAX_SKILL_LEVEL) {
//                    skillInstance.level = CommonSettings.MAX_SKILL_LEVEL;
//                }
//            }
//            for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//                internalSkillInstance.level += num;
//                if (internalSkillInstance.level > CommonSettings.MAX_INTERNALSKILL_LEVEL) {
//                    internalSkillInstance.level = CommonSettings.MAX_INTERNALSKILL_LEVEL;
//                }
//            }
//        }
//    }


//    public void addRandomTalentAndWeapons() {
//        this.addRandomTalent();
//        JyItem weapon = JyResourceManager.GetRandomInCondition < JyItem > (delegate(object item, out boolean used){
//            used = false;
//            return ((JyItem) item).type == 1;
//        });
//        if (weapon != null) {
//            JyItemInstance instance = new JyItemInstance {
//                name = weapon.name
//            } ;
//            int maxTriggerCount = Tools.getRandomInt(3, 7);
//            for (int i = 0; i < maxTriggerCount; i++) {
//                instance.AddRandomTrigger();
//            }
//            this.equipment.add(instance);
//        }
//
//        JyItem armor = JyResourceManager.GetRandomInCondition < JyItem > (delegate(object item, out boolean used){
//            used = false;
//            return ((JyItem) item).type == 2;
//        });
//        if (armor != null) {
//            JyItemInstance instance = new JyItemInstance {
//                name = armor.name
//            } ;
//            int maxTriggerCount = Tools.getRandomInt(3, 7);
//            for (int i = 0; i < maxTriggerCount; i++) {
//                instance.AddRandomTrigger();
//            }
//            this.equipment.add(instance);
//        }
//
//        JyItem accessory = JyResourceManager.GetRandomInCondition < JyItem > (delegate(object item, out boolean used){
//            used = false;
//            return ((JyItem) item).type == 3;
//        });
//        if (accessory != null) {
//            JyItemInstance instance = new JyItemInstance {
//                name = accessory.name
//            } ;
//            int maxTriggerCount = Tools.getRandomInt(3, 7);
//            for (int i = 0; i < maxTriggerCount; i++) {
//                instance.AddRandomTrigger();
//            }
//            this.equipment.add(instance);
//        }
//
//        JyItem book = JyResourceManager.GetRandomInCondition < JyItem > (delegate(object item, out boolean used){
//            used = false;
//            return ((JyItem) item).type == 4;
//        });
//        if (book != null) {
//            JyItemInstance instance = new JyItemInstance {
//                name = book.name
//            } ;
//            this.equipment.add(instance);
//        }
//    }


    //    private void addRandomTalent() {
//        String text = "";
//        int    num  = 0;
//        if (RuntimeData.Instance.gameMode == "hard") {
//            num = 1;
//        }
//        if (RuntimeData.Instance.gameMode == "crazy") {
//            num = 3;
//        }
//        if (RuntimeData.Instance.gameMode == "crazy") {
//            String enemyRandomTalentListCrazyAttack  = CommonSettings.GetEnemyRandomTalentListCrazyAttack();
//            String enemyRandomTalentListCrazyDefence = CommonSettings.GetEnemyRandomTalentListCrazyDefence();
//            String enemyRandomTalentListCrazyOther   = CommonSettings.GetEnemyRandomTalentListCrazyOther();
//            this.talents.add(enemyRandomTalentListCrazyAttack);
//            this.talents.add(enemyRandomTalentListCrazyDefence);
//            this.talents.add(enemyRandomTalentListCrazyOther);
//        } else {
//            for (int i = 0; i < num; i++) {
//                do {
//                    text = CommonSettings.GetEnemyRandomTalent(this.Female);
//                }
//                while (this.hasTalent(text));
//                this.talents.add(text);
//            }
//        }
//    }
    public String Book_Skill_bak = "";

//
//    public boolean HasEquipmentTalent(String talent) {
//        return this.EquipmentTalents.contains(talent);
//    }
//
//
//    public void addRoundSkillLevel_Zhenlongqiju() {
//        int num = RuntimeData.Instance.round / LuaManager.GetConfigInt("NPC_SKILL_LEVEL_ADD_BY_ZHOUMU");
//        if (num > 1) {
//            for (JySkillInstance skillInstance : this.skills) {
//                skillInstance.level += Tools.getRandomInt(0, 1);
//            }
//            for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//                internalSkillInstance.level += Tools.getRandomInt((int) (num / 10.0), (int) (num / 5.0));
//            }
//        }
//    }


    //    public boolean AddExp_Battle(int add, int maxattrib) {
//        this.exp += add;
//        JyItemInstance equipment = this.GetEquipment(4);
//        if (equipment != null) {
//            ItemSkill itemSkill = equipment.GetItemSkill();
//            if (itemSkill.isInternal && this.internalSkills.Count < BattleField.MAX_INTERNALSKILL_COUNT) {
//                boolean flag = false;
//                for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//                    if (internalSkillInstance.name.Equals(itemSkill.SkillName)) {
//                        flag = true;
//                        if (itemSkill.maxLevel >= internalSkillInstance.level) {
//                            internalSkillInstance.tryAddExp(add, itemSkill.maxLevel);
//                            break;
//                        }
//                        break;
//                    }
//                }
//                if (!flag) {
//                    JyInternalSkillInstance internalSkillInstance2 = new JyInternalSkillInstance {
//                        name = itemSkill.SkillName,
//                            level = 1,
//                            equipped = 0,
//                            owner = this
//                    } ;
//                    internalSkillInstance2.refreshUniqueSkills();
//                    this.internalSkills.add(internalSkillInstance2);
//                    internalSkillInstance2.tryAddExp(add, 0);
//                }
//            } else if (this.skills.Count < BattleField.MAX_SKILL_COUNT) {
//                boolean flag2 = false;
//                for (JySkillInstance skillInstance : this.skills) {
//                    if (skillInstance.name.Equals(itemSkill.SkillName)) {
//                        flag2 = true;
//                        if (itemSkill.maxLevel >= skillInstance.level) {
//                            skillInstance.tryAddExp(add, itemSkill.maxLevel);
//                            break;
//                        }
//                        break;
//                    }
//                }
//                if (!flag2) {
//                    JySkillInstance skillInstance2 = new JySkillInstance {
//                        name = itemSkill.SkillName,
//                            level = 1,
//                            owner = this
//                    } ;
//                    skillInstance2.refreshUniqueSkills();
//                    this.skills.add(skillInstance2);
//                    skillInstance2.tryAddExp(add, 0);
//                }
//            }
//        }
//        boolean result = false;
//        if (this.level >= BattleField.MAX_LEVEL) {
//            this.exp = 0;
//        }
//        while (this.exp > this.levelupExp && this.level < BattleField.MAX_LEVEL) {
//            int level = this.level;
//            this.level = level + 1;
//            this.leftpoint += 2;
//            this.maxhp += this.GrowTemplate().Attributes.get("hp");
//            if (this.maxhp > BattleField.MAX_HPMP) {
//                this.maxhp = BattleField.MAX_HPMP;
//            }
//            this.maxmp += this.GrowTemplate().Attributes.get("mp");
//            if (this.maxmp > BattleField.MAX_HPMP) {
//                this.maxmp = BattleField.MAX_HPMP;
//            }
//            if (this.bili + this.GrowTemplate().Attributes.get("bili") < maxattrib) {
//                this.bili += this.GrowTemplate().Attributes.get("bili");
//            } else {
//                this.bili = maxattrib;
//            }
//            if (this.fuyuan + this.GrowTemplate().Attributes.get("fuyuan") < maxattrib) {
//                this.fuyuan += this.GrowTemplate().Attributes.get("fuyuan");
//            } else {
//                this.fuyuan = maxattrib;
//            }
//            if (this.gengu + this.GrowTemplate().Attributes.get("gengu") < maxattrib) {
//                this.gengu += this.GrowTemplate().Attributes.get("gengu");
//            } else {
//                this.gengu = maxattrib;
//            }
//            if (this.dingli + this.GrowTemplate().Attributes.get("dingli") < maxattrib) {
//                this.dingli += this.GrowTemplate().Attributes.get("dingli");
//            } else {
//                this.dingli = maxattrib;
//            }
//            if (this.shenfa + this.GrowTemplate().Attributes.get("shenfa") < maxattrib) {
//                this.shenfa += this.GrowTemplate().Attributes.get("shenfa");
//            } else {
//                this.shenfa = maxattrib;
//            }
//            if (this.wuxing + this.GrowTemplate().Attributes.get("wuxing") < maxattrib) {
//                this.wuxing += this.GrowTemplate().Attributes.get("wuxing");
//            } else {
//                this.wuxing = maxattrib;
//            }
//            if (this.quanzhang + this.GrowTemplate().Attributes.get("quanzhang") < maxattrib) {
//                this.quanzhang += this.GrowTemplate().Attributes.get("quanzhang");
//            } else {
//                this.quanzhang = maxattrib;
//            }
//            if (this.jianfa + this.GrowTemplate().Attributes.get("jianfa") < maxattrib) {
//                this.jianfa += this.GrowTemplate().Attributes.get("jianfa");
//            } else {
//                this.jianfa = maxattrib;
//            }
//            if (this.daofa + this.GrowTemplate().Attributes.get("daofa") < maxattrib) {
//                this.daofa += this.GrowTemplate().Attributes.get("daofa");
//            } else {
//                this.daofa = maxattrib;
//            }
//            if (this.qimen + this.GrowTemplate().Attributes.get("qimen") < maxattrib) {
//                this.qimen += this.GrowTemplate().Attributes.get("qimen");
//            } else {
//                this.qimen = maxattrib;
//            }
//            result = true;
//        }
//        return result;
//    }
    public int    addmaxhp;
    public int    addmaxmp;
    public double DefanceValue;


//    public void SetRoleBattleValue() {
//        this.DefanceValue = this.getDefenceValue();
//        this.CriticalpValue = this.AttributesFinal.get("fuyuan") / 50.0 / 20.0 * (1f + this.GetEquippedInternalSkill().critical);
//        this.EquipmentCriticalpValue = this.criticalProbabilityAdd();
//        this.SubCriticalpPercent = 0.0;
//        this.EquipmentDefencePercent = this.getEquipmentDefencePercent(  this.SubCriticalpPercent);
//        this.AoyiBaseProbability = AoyiLogic.GetAoyiBaseProbability(this);
//        double num = 0f;
//        for (JyTrigger trigger : this.GetTriggers("xi")) {
//            num += double.Parse(trigger.Argvs()[0]) / 100f;
//        }
//        this.xiValue = num;
//        double num2 = 0.0;
//        for (JyTrigger trigger2 : this.GetTriggers("mingzhong")) {
//            num2 += Double.parseDouble(trigger2.Argvs()[0]) / 100.0;
//        }
//        if (num2 > 1.0) {
//            num2 = 1.0;
//        } else if (num2 < 0.01) {
//            num2 = 0.01;
//        }
//        this.mingzhongValue = num2;
//        double num3 = 0.0;
//        for (JyTrigger trigger3 : this.GetTriggers("anti_debuff")) {
//            num3 += Double.parseDouble(trigger3.Argvs()[0]) / 100.0;
//        }
//        if (num3 > 1.0) {
//            num3 = 1.0;
//        } else if (num3 < 0.001) {
//            num3 = 0.001;
//        }
//        this.anti_debuffValue = num3;
//        double num4  = 0.0;
//        double num5  = 1.0;
//        double num6  = 1.0;
//        double num7  = 1.0;
//        double num8  = 1.0;
//        double num9  = 1.0;
//        double num10 = 1.5;
//        for (JyTrigger trigger4 : this.GetAllTriggers()) {
//            String name = trigger4.name;
//            switch (name) {
//                case "attack":
//                    num4 += Double.parseDouble(trigger4.Argvs()[0]);
//                    break;
//                case "powerup_quanzhang":
//                    num5 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//                case "powerup_jianfa":
//                    num6 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//                case "powerup_daofa":
//                    num7 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//                case "powerup_qimen":
//                    num8 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//                case "powerup_xianshu":
//                    num9 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//                case "critical":
//                    num10 += Double.parseDouble(trigger4.Argvs()[0]) / 100.0;
//                    break;
//            }
//        }
//        this.attackValue = num4;
//        this.powerup_quanzhangValue = num5;
//        this.powerup_jianfaValue = num6;
//        this.powerup_daofaValue = num7;
//        this.powerup_qimenValue = num8;
//        this.powerup_xianshuValue = num9;
//        this.criticalValue = num10;
//    }


//    private String GetAttributeHpString() {
//        // this.internalSkills[0];
//        // this.internalSkills
//        int num               = this.Attributes.get("maxhp");
//        int num2              = this.GetAdditionAttribute("maxhp");
//        int additionAttribute = this.GetAdditionAttribute("maxhppercent");
//        if (additionAttribute != 0) {
//            num2 += (int) (num * (additionAttribute / 100.0));
//        }
//        return String.format("%s(+%s)", num.toString("###,###"), num2.toString("###,###"));
//    }


//    private String GetAttributeMpString() {
//        int num               = this.Attributes.get("maxmp");
//        int num2              = this.GetAdditionAttribute("maxmp");
//        int additionAttribute = this.GetAdditionAttribute("maxmppercent");
//        if (additionAttribute != 0) {
//            num2 += (int) (num * (additionAttribute / 100.0));
//        }
//        return String.format("%s(+%s)", num.toString("###,###"), num2.toString("###,###"));
//    }

    //    public JyInternalSkillInstance RandomInternalSkill() {
//        int r = new Random().Next(internalSkills.Count);
//        return internalSkills[r];
//    }
//
//    public JySkillInstance RandomSkill() {
//        int r = new Random().Next(skills.Count);
//        return skills[r];
//    }
    public  double CriticalpValue;
    public  double EquipmentCriticalpValue;
    public  double EquipmentDefencePercent;
    public  double SubCriticalpPercent;
    public  double Difficulty;
    public  double AoyiBaseProbability;
    public  double xiValue;
    public  double mingzhongValue;
    public  double anti_debuffValue;
    public  double attackValue;
    public  double powerup_quanzhangValue;
    public  double powerup_jianfaValue;
    public  double powerup_daofaValue;
    public  double powerup_qimenValue;
    public  double powerup_xianshuValue;
    public  double criticalValue;
    public  String BakTalents;
    private int    _level;


    public JyRole() {
        this.AttributesFinal = new AttributeFinalHelper(this);
        this.Attributes = new AttributeHelper(this);
    }

    public static JyRole Generate(String key) {
        return JyResourceManager.get(JyRole.class, key);
    }

    // (get) Token: 0x06000457 RID: 1111 RVA: 0x00004624 File Offset: 0x00002824
    // [XmlIgnore]
    @Override public /*override*/ String getPK() {
        {
            return this.key;
        }
    }

//    @Override public /*override*/ void initBind() {
//        for (JySkillInstance skillInstance : this.skills) {
//            skillInstance.owner = this;
//            skillInstance.refreshUniqueSkills();
//            for (UniqueSkillInstance uniqueSkillInstance : skillInstance.uniqueSkills) {
//                uniqueSkillInstance.owner = this;
//            }
//        }
//        for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//            internalSkillInstance.owner = this;
//            internalSkillInstance.refreshUniqueSkills();
//            for (UniqueSkillInstance uniqueSkillInstance2 : internalSkillInstance.uniqueSkills) {
//                uniqueSkillInstance2.owner = this;
//            }
//        }
//        for (JySpecialSkillInstance specialSkillInstance : this.specialSkills) {
//            specialSkillInstance.owner = this;
//        }
//        this.hp = this.maxhp;
//        this.mp = this.maxmp;
//    }

    public String GetAnimation() {
//            using (IEnumerator<JyTrigger> enumerator = this.GetTriggers("animation").GetEnumerator()) {
//                if (enumerator.MoveNext()) {
//                    JyTrigger trigger = enumerator.Current;
//                    return trigger.Argvs()[1];
//                }
//            }
        return this.animation;
    }

    // (get) Token: 0x0600045C RID: 1116 RVA: 0x0000463A File Offset: 0x0000283A
    // [XmlIgnore]
    public int wuxue() {
        {
            return 100 + this.Level() * this.GrowTemplate().Attributes.get("wuxue");
        }
    }

    // (get) Token: 0x0600045D RID: 1117 RVA: 0x0000465B File Offset: 0x0000285B
    // (set) Token: 0x0600045E RID: 1118 RVA: 0x00004663 File Offset: 0x00002863
    public int level() {
        {
            return this._level;
        }
    }

    public void setLevel(int value) {
        this._level = value;
        this.exp = this.PrevLevelupExp();

    }

    // (get) Token: 0x0600045F RID: 1119 RVA: 0x00004678 File Offset: 0x00002878
    public int Level() {
        {
            return this.level();
        }
    }

    // (get) Token: 0x06000460 RID: 1120 RVA: 0x00004680 File Offset: 0x00002880
    // (set) Token: 0x06000461 RID: 1121 RVA: 0x00004688 File Offset: 0x00002888
    // [XmlIgnore]
    public int Exp() {
        {
            return this.exp;
        }
    }

    public void setExp(int value) {
        this.exp = value;

    }

    // (get) Token: 0x06000462 RID: 1122 RVA: 0x00004691 File Offset: 0x00002891
    public boolean Arena() {
        {
            return this.arenaValue != "no";
        }
    }

    // (get) Token: 0x06000463 RID: 1123 RVA: 0x000046A3 File Offset: 0x000028A3
    public boolean Female() {
        {
            return this.femaleValue == 1;
        }
    }

    // (get) Token: 0x06000464 RID: 1124 RVA: 0x000046AE File Offset: 0x000028AE
    // (set) Token: 0x06000465 RID: 1125 RVA: 0x0002E174 File Offset: 0x0002C374
//     public String TalentValue() {
//        {
//            return TextUtils.join("#", this.talents);
//        }
//    }

    public void setTalentValue(String value) {
        this.talents.clear();
        for (String text : value.split("#")) {
            if (!TextUtils.isEmpty(text)) {
                this.talents.add(text);
            }
        }

    }


    // [XmlIgnore]
//        public BattleSprite Sprite;

    // (get) Token: 0x06000466 RID: 1126 RVA: 0x0002E1C4 File Offset: 0x0002C3C4
    // [XmlIgnore]
    public JyRoleGrowTemplate GrowTemplate() {

        JyRoleGrowTemplate roleGrowTemplate = JyResourceManager.get(JyRoleGrowTemplate.class, this.growTemplateValue);
        if (roleGrowTemplate == null) {
            roleGrowTemplate = JyResourceManager.get(JyRoleGrowTemplate.class, "default");
        }
        return roleGrowTemplate;

    }

    public JyItemInstance GetEquipment(ItemType type) {
        return this.GetEquipment(type);
    }

    public JyItemInstance GetEquipment(int type) {
        if (this.equipment == null) {
            return null;
        }
//        for (JyItemInstance itemInstance : this.equipment) {
//            if (itemInstance.type() == type) {
//                return itemInstance;
//            }
//        }
        return null;
    }

    public void Reset(boolean recover) {
        if (recover) {
            this.hp = this.Attributes.get("maxhp");
            this.mp = this.Attributes.get("maxmp");
        } else {
            if (this.Attributes.get("hp") <= 0) {
                this.hp = 1;
            }
            if (this.Attributes.get("mp") <= 0) {
                this.mp = 1;
            }
        }
        this.balls = 0;
        this.SkillCdRecover();
    }

    public void SkillCdRecover() {
//        for (JySkillInstance skillInstance : this.skills) {
////            skillInstance.currentCd = 0;
////            for (UniqueSkillInstance uniqueSkillInstance : skillInstance.uniqueSkills) {
////                uniqueSkillInstance.currentCd = 0;
////            }
////        }
////        for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
////            for (UniqueSkillInstance uniqueSkillInstance2 : internalSkillInstance.uniqueSkills) {
////                uniqueSkillInstance2.currentCd = 0;
////            }
////        }
////        for (JySpecialSkillInstance specialSkillInstance : this.specialSkills) {
////            specialSkillInstance.currentCd = 0;
////        }
    }

    // (get) Token: 0x0600046C RID: 1132 RVA: 0x000046DB File Offset: 0x000028DB
    // [XmlIgnore]
    public int LevelupExp() {
        {
            return CommonSettings.LevelupExp(this.Level());
        }
    }

    // (get) Token: 0x0600046D RID: 1133 RVA: 0x000046E8 File Offset: 0x000028E8
    // [XmlIgnore]
    public int PrevLevelupExp() {
        {
            return CommonSettings.LevelupExp(this.Level() - 1);
        }
    }

    public boolean HasTalent(String talent) {
        if (this.talents.contains(talent)) {
            return true;
        }
        if (this.EquipmentTalents().contains(talent)) {
            return true;
        }
        JyInternalSkillInstance equippedInternalSkill = this.GetEquippedInternalSkill();
        return equippedInternalSkill != null && equippedInternalSkill.hasTalent(talent);
    }

    // (get) Token: 0x06000471 RID: 1137 RVA: 0x0002E4C8 File Offset: 0x0002C6C8
    // [XmlIgnore]
    public List<String> EquipmentTalents() {
        {
            List<String> visitedTalent = new ArrayList<String>();
//            for (JyTrigger t : this.GetTriggers("talent")) {
//                String talentName = t.Argvs()[0];
//                if (t.name == "talent" && !visitedTalent.contains(talentName)) {
//                    visitedTalent.add(talentName);
//                }
//            }
//            for (JyItemInstance t2 : this.equipment) {
//                if (t2 != null) {
//                    for (String talentName2 : t2.talents()) {
//                        if (!visitedTalent.contains(talentName2)) {
//                            visitedTalent.add(talentName2);
//                        }
//                    }
//                }
//            }
        }
        return null;
    }

    public JyInternalSkillInstance GetEquippedInternalSkill() {
//        for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//            if (internalSkillInstance.isUsed()) {
//                return internalSkillInstance;
//            }
//        }
        return null;
    }

    public void SetEquippedInternalSkill(JyInternalSkillInstance skill) {
//        for (JyInternalSkillInstance internalSkillInstance : this.internalSkills) {
//            internalSkillInstance.equipped = 0;
//        }
        skill.equipped = 1;
    }

    // (get) Token: 0x06000475 RID: 1141 RVA: 0x00004749 File Offset: 0x00002949
    // [XmlIgnore]
    public boolean Animal() {
        {
            return this.Attributes.get("female") == -1;
        }
    }

    public Iterable<JyTrigger> GetTriggers(String name) {
        List<JyTrigger> triggers = new ArrayList<>();
//        for (JyItemInstance item : this.equipment) {
//            for (JyTrigger t : item.allTriggers()) {
//                if (t.name == name) {
//                    triggers.add(t);
//                }
//            }
//        }
//        for (JySkillInstance s : this.skills) {
//            for (JyTrigger t2 : s.Skill().triggers) {
//                if (s.level >= t2.level && t2.name == name) {
//                    triggers.add(t2);
//                }
//            }
//        }
//        for (JyInternalSkillInstance s2 : this.internalSkills) {
//            for (JyTrigger t3 : s2.internalSkill().triggers) {
//                if (s2.level >= t3.level && t3.name == name) {
//                    triggers.add(t3);
//                    ;
//                }
//            }
//        }
        return triggers;
    }

    public int GetAdditionAttribute(String attribute) {
        String b   = CommonSettings.AttributeToChinese(attribute);
        int    num = 0;
        for (JyTrigger trigger : this.GetTriggers("attribute")) {
            if (trigger.Argvs()[0] == b) {
                num += Integer.parseInt(trigger.Argvs()[1]);
            }
        }

        if ((this.HasTalent("兵魂") && (
            attribute.equals("quanzhang")
                || attribute.equals("jianfa")
                || attribute.equals("daofa")
                || attribute.equals("qimen")))
            || (this.HasTalent("力王") && attribute.equals("bili"))
            || (this.HasTalent("风驰") && attribute.equals("shenfa"))
            || (this.HasTalent("悟心") && attribute.equals("wuxing"))
            || (this.HasTalent("轮回") && attribute.equals("fuyuan"))
            || (this.HasTalent("铁骨") && attribute.equals("gengu"))
            || (this.HasTalent("坚韧") && attribute.equals("dingli"))
            || (this.HasTalent("命魂") && attribute.equals("maxhp"))
            || (this.HasTalent("气魄") && attribute.equals("maxmp"))) {
            num *= 2;
        }

        if (!attribute.equals("maxhp") && !attribute.equals("maxmp")
            && !attribute.equals("maxhppercent") && !attribute.equals("maxmppercent")) {
            if (this.HasTalent("武学奇才")) {
                num *= 3;
            }
        }

        //if (num > 3000) {
        //    num = 3000;
        //}
        return num;
    }

    public int getSkillTypeValue() {
        return this.AttributesFinal.get("quanzhang") + this.AttributesFinal.get("jianfa")
            + this.AttributesFinal.get("daofa") + this.AttributesFinal.get("qimen");
    }

    public int getMaxSkillTypeValue() {
        int quanzhang = this.AttributesFinal.get("quanzhang");
        int jianfa    = this.AttributesFinal.get("jianfa");
        int daofa     = this.AttributesFinal.get("daofa");
        int qimen     = this.AttributesFinal.get("qimen");

        return Math.max(Math.max(quanzhang, jianfa), Math.max(qimen, daofa));
    }

    // (get) Token: 0x0600047C RID: 1148 RVA: 0x0002E944 File Offset: 0x0002CB44
    // [XmlIgnore]
    public double defence() {
        {
            if (CommonSettings.MOD_KEY == 1) {
                double dingli_ajust    = this.AttributesFinal.get("dingli") / 40.0;
                double gengu_ajust     = this.AttributesFinal.get("gengu") / 70.0;
                double equipment_ajust = this.GetEquippedInternalSkill().defence();

                double base_value = 150.0 + (10.0 + dingli_ajust + gengu_ajust) * 8.0 * (1f + equipment_ajust);
                double num        = base_value;
                for (JyTrigger trigger : this.GetTriggers("defence")) {
                    num += Double.parseDouble(trigger.Argvs()[0]);
                }

                double attack_ajust = AttackLogic.defenceDescAttack(num);
                double result       = maxhp / (1.0 - attack_ajust) / 30.0;
                return result;
            } else {
                double attack_ajust = this.getDefenceDescAttack();

                double result = maxhp / (1.0 - attack_ajust) / 30.0;
                return result;
            }
        }
    }

    // (get) Token: 0x0600047D RID: 1149 RVA: 0x0002EA60 File Offset: 0x0002CC60
    // [XmlIgnore]
    public double attack() {
        {
//            double num = 1.0;
//            num *= 4.0 + this.AttributesFinal.get("bili") / 120.0;
//            num *= 2.0 + this.getMaxSkillTypeValue() / 200.0;
//            num *= 1f + this.GetEquippedInternalSkill().attack();
//            for (JyTrigger trigger : this.GetTriggers("attack")) {
//                num += Double.parseDouble(trigger.Argvs()[0]) / 35.0;
//            }
//            double num2 = this.AttributesFinal.get("fuyuan") / 50.0 / 20.0 * (1f + this.GetEquippedInternalSkill().critical()) + this.criticalProbabilityAdd();
//            if (num2 > 1.0) {
//                num2 = 1.0;
//            }
//            int num3 = 0;
//            for (JyTrigger trigger2 : this.GetTriggers("critical")) {
//                num3 += Integer.parseInt(trigger2.Argvs()[0]);
//            }
//            num *= 1.0 + num2 * (1.5 + num3 / 100.0);
//            double num4 = 0.0;
//            for (JySkillInstance skillInstance : this.skills) {
//                if (skillInstance.power() > num4) {
//                    num4 = skillInstance.power();
//                }
//            }
//            if (Math.abs(num4) < 0.000001) {
//                for (UniqueSkillInstance uniqueSkillInstance : this.GetEquippedInternalSkill().uniqueSkills) {
//                    if (uniqueSkillInstance.power() > num4) {
//                        num4 = uniqueSkillInstance.power();
//                    }
//                }
//            }
//            return num * num4;
            return 0;
        }
    }

    public double criticalProbabilityAdd() {
        double num = 0f;
        for (JyTrigger trigger : this.GetTriggers("criticalp")) {
            num += (double) (Float.parseFloat(trigger.Argvs()[0]) / 100.0);
        }
        for (JyTrigger trigger2 : this.GetTriggers("attack")) {
            num += (double) (Integer.parseInt(trigger2.Argvs()[1]) / 100.0);
        }
        return num;
    }

    public int getTotalWuxueCost() {
        int num = 0;
        for (String talent : this.talents) {
            num += JyResource.getTalentCost(talent);
        }
        return num;
    }

    public boolean hasRoleTalent(String talent) {
        if (this.talents.contains(talent)) {
            return true;
        }
        JyInternalSkillInstance equippedInternalSkill = this.GetEquippedInternalSkill();
        return equippedInternalSkill != null && equippedInternalSkill.hasTalent(talent);
    }

    private double getDefenceDescAttack() {
        double defanceValue = this.getDefenceValue();
        double num          = 0.0;
        for (JyTrigger trigger : this.GetTriggers("defence")) {
            num += Double.parseDouble(trigger.Argvs()[0]);
        }
        return AttackLogic.defenceDescAttack(defanceValue) + AttackLogic.defenceDescAttack2(num);
    }

    public double getDefenceValue() {
        double dingliAdjust        = this.AttributesFinal.get("dingli");
        double genguAdjust         = this.AttributesFinal.get("gengu");
        double internalSkillAdjust = this.GetEquippedInternalSkill().defence();

        if (CommonSettings.MOD_KEY == 1) {
            return 150.0 + (10.0 + dingliAdjust / 500.0 + genguAdjust / 500.0) * (1f + internalSkillAdjust);
        }
        return 150.0 + (10.0 + dingliAdjust / 40.0 + genguAdjust / 70.0) * 8.0 * (1f + internalSkillAdjust);
    }

    private double getEquipmentDefencePercent(Double subCriticalP) {
        double num = 0.0;
        for (JyTrigger trigger : this.GetTriggers("defence")) {
            num += Double.parseDouble(trigger.Argvs()[0]);
            subCriticalP += Double.parseDouble(trigger.Argvs()[1]) / 100.0;
        }
        return AttackLogic.defenceDescAttack2(num);
    }
}
